package org.aizuomeng.config.SpringSecurity;

import com.alibaba.fastjson.JSON;
import org.aizuomeng.common.api.Result;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @email 839013329@qq.com
 * @author: LuHaoLong
 * @date: 2021/12/29
 * @time: 10:35
 * @description:  无权访问
 */
@Component
public class AjaxAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
        httpServletResponse.getWriter().write(JSON.toJSONString(Result.error(401,"权限不足")));
    }
}
